﻿using System.Collections.Generic;
using MiHoMiao.Mono.UnityPool;
using TodoList.Mono.TaskCreator;
using TodoList.TodoTask;
using UnityEngine;

namespace TodoList.Mono.MainObject
{
    public partial class Main
    {
        public void CreateTaskTodo()
        {
            UnityPool<TaskGenerator>.GetUI(TaskGeneratorPrefab, transform);
        }

        public void ShowDone()
        {
            float num = 1 - DoneImage.color.r;
            DoneImage.color = new Color(num, num, num);
            Refresh(num > 0.5f
                ? $"select * from {nameof(TodoTaskTable)} where {nameof(TodoTaskTable.IsDone)} = 0"
                : $"select * from {nameof(TodoTaskTable)}"
            );
        }
        
        private readonly List<TodoTask.TodoTaskItem> m_Prefabs = new List<TodoTask.TodoTaskItem>();
        
        private void OpenAllPrefabs(IEnumerable<TodoTaskTable> targets)
        {
            foreach (TodoTaskTable item in targets)
            {
                TodoTask.TodoTaskItem newObject = UnityPool<TodoTask.TodoTaskItem>.Get(ItemPrefab, ItemContainer);
                newObject.SetId(item.Id);
                m_Prefabs.Add(newObject);
            }
        }
        
        private void CloseAllPrefabs()
        {
            foreach (TodoTask.TodoTaskItem item in m_Prefabs)
                UnityPool<TodoTask.TodoTaskItem>.Push(item);
            m_Prefabs.Clear();
        }


    }
}